package org.come.entity;


import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.come.bean.ColorScheme;
import org.come.bean.ConfigureBean;
import org.come.model.Configure;
import org.come.socket.GameClient;
import org.come.until.AnalysisString;
import org.come.until.GoodsListFromServerUntil;
import org.come.until.JmSum;
import org.come.until.UserMessUntil;

import com.gl.util.LingXiUtil;
import com.tool.tcp.NewPart;
import com.tool.tcp.SpriteFactory;

/**
 * 召唤兽实体类
 *
 * @author 叶豪芳
 * @date : 2017年11月23日 下午2:59:18
 */

public class RoleSummoning {

	// ID
	private BigDecimal sid;
	// 召唤兽ID
	private String summoningid;
	// 皮肤
	private String summoningskin;
	// 是否物理怪
	private String stye;
	// 血量
	private int hp;
	// 蓝量
	private int mp;
	// 伤害
	private int ap;
	// 敏捷
	private int sp;
	// 最高成长率
	private String growlevel;
	// 当前血量
	private long basishp;
	// 当前蓝量
	private long basismp;
	//（龙骨）
	private int dragon;
	//（超级龙骨）
	private int spdragon;
	// 坐骑抗性
	private String zqk;
	// 炼妖抗性
	private String lyk;
	// 天生抗性
	private String resistance;
	// 内丹抗性
//	private String NedanResistance;
	// 召唤兽技能属性
	private String skillData;
	// 炼妖次数
	private int alchemynum;
	// 技能
	private String skill;
	// 金
	private String gold;
	// 木
	private String wood;
	// 土
	private String soil;
	// 水
	private String water;
	// 火
	private String fire;
	// 召唤兽名称
	private String summoningname;
	// 宝宝类型
	private String ssn;
	// 角色ID
	private BigDecimal roleid;
	// 根骨
	private Integer bone;
	// 灵性
	private Integer spir;
	// 力量
	private Integer power;
	// 敏捷
	private Integer speed;
	// 定力
	private Integer calm;
	// 等级
	private Integer grade;
	// 经验
	private BigDecimal exp;
	// 忠诚度
	private Integer faithful;
	// 亲密值
	private Long friendliness;
	// 有几个召唤兽技能框解开了封印（初始值为1）
	private Integer openSeal;
	private Integer openql;
	// 内丹 物品id|物品id
	private String innerGoods;
	// 技能 静态表id|静态表id|静态表id...
	private String petSkills;
	private String petQlSkills;
	// 神兽技能id
	private String beastSkills;
	// 被点化次数
	private int revealNum;
	// 使用神兽飞升丹的次数
	private int flyupNum;
	// 使用成长进阶丹的次数
	private int czjjd;
	// 召唤兽增加四种属性几率字段
	private String fourattributes;
	// 使用元气丹的属性*1000
	private int growUpDanNum;
	//变色方案
	private String ColorScheme;
	//龙涎丸使用次数
	private int draC;
	//	32位   倒着数 技能开封数0-3 龙骨4-7 炼妖8-11 点化次数12-15 使用神兽飞升丹的次数16-19 龙涎丸20-23 转生次数24-27
	// 培养值
	private int trainNum;
	//召唤兽是否有加锁
	private int petlock;
	//召唤兽灵犀
	private String lingxi;
	// 悟灵技能  静态表id=1|静态表id=1|静态表id=1 最多3个
	private String petSkillswl;
	// 贵重
	private String quality;
	// 剩余时间
	private String surplusTimes;
	private Integer petTimeLock;
	private Long timeLock;
	//宠物跟随
	private boolean show;

	//已加锁的技能
	private String petSkilllock;

	private String summoningnameg;


	private String xinyuan;

	private String xy;

	private Map<BigDecimal, Goodstable> neiDan;

	private Goodstable cjs;
	private Goodstable part1;
	private Goodstable part2;
	private Goodstable part3;
	private int fragment;
	private String summoningNewskin;

	private int lzjdragon;//龙之精
	private int lzpdragon;//龙之魄
	private String hhschedule;

	private String refine;


	public String getXinyuan() {
		return this.xinyuan;
	}
	public void setXinyuan(String xinyuan) {
		this.xinyuan = xinyuan;
	}

	public String getSummoningNewskin() {
		return summoningNewskin;
	}

	public int getFragment() {
		return fragment;
	}

	public void setFragment(int fragment) {
		this.fragment = fragment;
	}
	public NewPart getHallucinationAdornPart(int skin,String ColorScheme){
		return SpriteFactory.createPart(skin,5,1,ColorScheme);
	}
	public NewPart getNewPart() {

			NewPart part = SpriteFactory.createPart(summoningNewskin, 9, 1, ColorScheme);
			part = part.addPart(getAdornPart());
			return part;


	}
	public void setSummoningNewskin(String summoningNewskin) {
		this.summoningNewskin = summoningNewskin;
	}

	public int getTrainNum() {
		return trainNum;
	}
	public void setTrainNum(int trainNum) {
		this.trainNum = trainNum;
	}

	/**4大基础属性 数值加成*/
	public void getSI(int[] pets) {
		if (skillData == null || skillData.equals(""))
			return;
		String[] v = skillData.split("\\|");
		for (int i = 0; i < v.length; i++) {
			String[] v1 = v[i].split("=");
			if (v1[0].equals("HP")){
				pets[0]+=Double.parseDouble(v1[1]);
			}else if (v1[0].equals("MP")) {
				pets[1]+=Double.parseDouble(v1[1]);
			}else if (v1[0].equals("AP")) {
				pets[2]+=Double.parseDouble(v1[1]);
			}else if (v1[0].equals("SP")) {
				pets[3]+=Double.parseDouble(v1[1]);
			}
		}
	}

	/**灵犀加成*/
	public void getLX(int[] pets) {
		if (lingxi == null || lingxi.equals(""))
			return;
		String[] lx = lingxi.split("&");
		String[] v = lx[3].split("=")[1].split("\\|");
		for (int i = 0; i < v.length; i++) {
			String[] v1 = v[i].split("_");
			int lvl = Integer.parseInt(v1[1]);
			if (lvl == 0) {
				continue;
			}
			if (v1[0].equals("11001")){
				pets[0]+=LingXiUtil.getNumberBySkillId(v1[0],1,lvl);
			}else if (v1[0].equals("11002")) {
				pets[1]+=LingXiUtil.getNumberBySkillId(v1[0],1,lvl);
			}else if (v1[0].equals("11003")) {
				pets[2]+=LingXiUtil.getNumberBySkillId(v1[0],1,lvl);
			}else if (v1[0].equals("11004")) {
				pets[3]+=LingXiUtil.getNumberBySkillId(v1[0],1,lvl);
			}
		}
	}

	//改变显示素材
	public NewPart getPart(){
		NewPart part=SpriteFactory.createPart(summoningskin, 9, 1, ColorScheme);
		part=part.addPart(getAdornPart());
		return part;
	}
	/**获取召唤兽饰品皮肤  召唤兽类型 |部件-物品id-额外-额外*/
	public NewPart getAdornPart(){
		if (stye==null||stye.equals("")) {
			return null;
		}
		String[] v=stye.split("\\|");
		for (int i = 1; i < v.length; i++) {
			String[] vs=v[i].split("-");
			if (vs[0].equals("3")) {
				if (vs.length<=2) {return null;}
				String color=null;
				if (vs.length>3) {
					ColorScheme value=UserMessUntil.getColor(vs[3]);
					if (value!=null) {
						color=value.getValue();
					}
				}
				NewPart part=SpriteFactory.createPart(vs[2],9,1,color);
				return part;
			}
		}
		return null;
	}
	public BigDecimal getSid() {
		return sid;
	}
	public void setSid(BigDecimal sid) {
		this.sid = sid;
	}
	public String getSummoningid() {
		return summoningid;
	}
	public void setSummoningid(String summoningid) {
		this.summoningid = summoningid;
	}
	public String getSummoningskin() {
		return summoningskin;
	}
	public void setSummoningskin(String summoningskin) {
		this.summoningskin = summoningskin;
	}
	public String getStye() {
		return stye;
	}
	public void setStye(String stye) {
		this.stye = stye;
	}


	public long getBasishp() {
		return basishp;
	}
	public void setBasishp(long basishp) {
		this.basishp = basishp <= 0 ? 1 : basishp;
	}
	public long getBasismp() {
		return basismp;
	}
	public void setBasismp(long mp_Current) {
		this.basismp = mp_Current;
	}

	public long getBasishps() {
		return basishp;
	}
	public void setBasishps(int basishp) {
		this.basishp = basishp <= 0 ? 1 : basishp;
	}
	public long getBasismps() {
		return basismp;
	}
	public void setBasismps(int basismp) {
		this.basismp = basismp;
	}

	public String getGrowlevel() {
		return growlevel;
	}
	public void setGrowlevel(String growlevel) {
		this.growlevel = growlevel;
	}
	public String getResistance() {
		return resistance;
	}
	public void setResistance(String resistance) {
		this.resistance = resistance;
	}
	public String getSkill() {
		return skill;
	}
	public void setSkill(String skill) {
		this.skill = skill;
	}
	public String getGold() {
		if (gold==null||gold.equals(""))gold="0";
		return gold;
	}
	public void setGold(String gold) {
		this.gold = gold;
	}
	public String getWood() {
		if (wood==null||wood.equals(""))wood="0";
		return wood;
	}
	public void setWood(String wood) {
		this.wood = wood;
	}
	public String getSoil() {
		if (soil==null||soil.equals(""))soil="0";
		return soil;
	}
	public void setSoil(String soil) {
		this.soil = soil;
	}
	public String getWater() {
		if (water==null||water.equals(""))water="0";
		return water;
	}
	public void setWater(String water) {
		this.water = water;
	}
	public String getFire() {
		if (fire==null||fire.equals(""))fire="0";
		return fire;
	}
	public void setFire(String fire) {
		this.fire = fire;
	}
	public String getSummoningname() {
		return summoningname;
	}
	public void setSummoningname(String summoningname) {
		this.summoningname = summoningname;
	}
	public String getSsn() {
		return ssn;
	}
	public void setSsn(String ssn) {
		this.ssn = ssn;
	}
	public BigDecimal getRoleid() {
		return roleid;
	}
	public void setRoleid(BigDecimal roleid) {
		this.roleid = roleid;
	}

	public int getHp() {
		return (int) JmSum.MZ(hp);
	}
	public void setHp(int hp) {
		this.hp=(int) JmSum.ZM(hp);
	}
	public int getMp() {
		return (int) JmSum.MZ(mp);
	}
	public void setMp(int mp) {
		this.mp=(int) JmSum.ZM(mp);
	}
	public int getAp() {
		return (int) JmSum.MZ(ap);
	}
	public void setAp(int ap) {
		this.ap=(int) JmSum.ZM(ap);
	}
	public int getSp() {
		return (int) JmSum.MZ(sp);
	}
	public void setSp(int sp) {
		this.sp=(int) JmSum.ZM(sp);
	}
	public Integer getBone() {
		return (int) JmSum.MZ(bone);
	}
	public void setBone(Integer bone) {
		this.bone=(int) JmSum.ZM(bone);
	}
	public Integer getSpir() {
		return (int) JmSum.MZ(spir);
	}
	public void setSpir(Integer spir) {
		this.spir=(int) JmSum.ZM(spir);
	}
	public Integer getPower() {
		return (int) JmSum.MZ(power);
	}
	public void setPower(Integer power) {
		this.power=(int) JmSum.ZM(power);
	}
	public Integer getSpeed() {
		return (int) JmSum.MZ(speed);
	}
	public void setSpeed(Integer speed) {
		this.speed=(int) JmSum.ZM(speed);
	}
	public Integer getCalm() {
		if (calm==null) {setCalm(0);}
		return (int) JmSum.MZ(calm);
	}
	public void setCalm(Integer calm) {
		this.calm=(int) JmSum.ZM(calm);
	}
	public int getCanpoint(){
		int lvl=getGrade();
		int Turn=AnalysisString.petTurnRount(lvl);
		lvl=AnalysisString.petLvlint(lvl);
		int canpoint=lvl*8;
		if (Turn>=4) {canpoint+=lvl;}
		canpoint+=Turn*30;
		canpoint-=getBone();
		canpoint-=getSpir();
		canpoint-=getPower();
		canpoint-=getSpeed();
		canpoint-=getCalm();
		return canpoint;
	}
	public Integer getGrade() {
		return (int) JmSum.MZ(grade);
	}

	public void setGrade(Integer grade) {
		this.grade=(int) JmSum.ZM(grade);
	}

	public BigDecimal getExp() {
		return new BigDecimal(JmSum.MZ(exp.longValue()));
	}

	public void setExp(BigDecimal exp) {
		this.exp=new BigDecimal(JmSum.ZM(exp.longValue()));
	}

	public Long getFriendliness() {
		if (friendliness==null)setFriendliness(0L);
		return JmSum.MZ(friendliness);
	}

	public void setFriendliness(Long friendliness) {
		ConfigureBean allConfigure = UserMessUntil.getConfigureBean();
		Map<BigDecimal, Configure> item = allConfigure.getAllConfigure();
		Configure configure = item.get(new BigDecimal(1));
		if (friendliness>Integer.parseInt(configure.getZhsqmsx()))friendliness=Long.parseLong(configure.getZhsqmsx());
		this.friendliness=JmSum.ZM(friendliness);
	}

	public Integer getFaithful() {
		return faithful;
	}

	public void setFaithful(Integer faithful) {
		this.faithful = faithful;
	}

	public void addFaithful(Integer faithful) {
		if (faithful == null)
			this.faithful = 0;
		this.faithful += faithful;
		if (this.faithful < 0)
			this.faithful = 0;
		if (this.faithful > 100)
			this.faithful = 100;
	}

	public int getDragon() {
		return dragon;
	}

	public void setDragon(int dragon) {
		this.dragon = dragon;
	}

	public int getSpdragon() {
		return spdragon;
	}

	public void setSpdragon(int spdragon) {
		this.spdragon = spdragon;
	}

	public int getAlchemynum() {
		return alchemynum;
	}

	public void setAlchemynum(int alchemynum) {
		this.alchemynum = alchemynum;
	}

	public Integer getOpenSeal() {
		return openSeal;
	}

	public void setOpenSeal(Integer openSeal) {
		this.openSeal = openSeal;
	}
	public Integer getOpenql() {
		return openql;
	}

	public void setOpenql(Integer openql) {
		this.openql = openql;
	}
	public String getInnerGoods() {
		return innerGoods;
	}

	public void setInnerGoods(String innerGoods) {
		this.innerGoods = innerGoods;
	}

	public String getPetSkills() {
		return petSkills;
	}
	public String getPetQlSkills() {
		return this.petQlSkills;
	}
	public int getTurnRount() {
		return AnalysisString.petTurnRount(getGrade());
	}

	public int getRevealNum() {
		return revealNum;
	}

	public void setRevealNum(int revealNum) {
		this.revealNum = revealNum;
	}

	public int getFlyupNum() {
		return flyupNum;
	}

	public void setFlyupNum(int flyupNum) {
		this.flyupNum = flyupNum;
	}

	public int getCzjjd() {
		return czjjd;
	}
	public void setCzjjd(int czjjd) {
		this.czjjd = czjjd;
	}
	public String getBeastSkills() {
		return beastSkills;
	}

	public void setBeastSkills(String beastSkills) {
		this.beastSkills = beastSkills;
	}

	public String getFourattributes() {
		return fourattributes;
	}

	public void setFourattributes(String fourattributes) {
		this.fourattributes = fourattributes;
	}

	public String getSkillData() {
		return skillData;
	}

	public void setSkillData(String skillData) {
		this.skillData = skillData;
	}
	public String getPetSkillswl() {
		return petSkillswl;
	}

	public void setPetSkillswl(String petSkillswl) {
		this.petSkillswl = petSkillswl;
	}
	public String getZqk() {
		return zqk;
	}

	public void setZqk(String zqk) {
		this.zqk = zqk;
	}

	public String getLyk() {
		return lyk;
	}

	public void setLyk(String lyk) {
		this.lyk = lyk;
	}

	public int getGrowUpDanNum() {
		return growUpDanNum;
	}

	public void setGrowUpDanNum(int growUpDanNum) {
		this.growUpDanNum = growUpDanNum;
	}
	public String getColorScheme() {
		return ColorScheme;
	}
	public void setColorScheme(String colorScheme) {
		ColorScheme = colorScheme;
	}
	public int getDraC() {
		return draC;
	}
	public void setDraC(int draC) {
		this.draC = draC;
	}
	public int getPetlock() {
		return petlock;
	}
	public void setPetlock(int petlock) {
		this.petlock = petlock;
	}
	public String getLingxi() {
		return lingxi;
	}
	public void setLingxi(String lingxi) {
		this.lingxi = lingxi;
	}
	public Integer getZBone() {/**根骨*/
		return getBone()+getExtra("根骨");
	}
	public void setZBone(Integer bone) {
		setBone(bone-getExtra("根骨"));
	}
	public Integer getZSpir() {/**灵性*/
		return getSpir()+getExtra("灵性");
	}
	public void setZSpir(Integer spir) {
		setSpir(spir-getExtra("灵性"));
	}
	public Integer getZPower() {/**力量*/
		return getPower()+getExtra("力量");
	}
	public void setZPower(Integer power) {
		setPower(power-getExtra("力量"));
	}
	public Integer getZSpeed() {/**敏捷*/
		return getSpeed()+getExtra("敏捷");
	}
	public void setZSpeed(Integer speed) {
		setSpeed(speed-getExtra("敏捷"));
	}
	public Integer getZCalm() {/**定力*/
		return getCalm()+getExtra("定力");
	}
	public void setZCalm(Integer calm) {
		setCalm(calm-getExtra("定力"));
	}
	/**获取额外属性*/
	public int getExtra(String type){
		if (stye==null||stye.length()<=1) {return 0;}
		type+="=";
		int value=0;
		String[] v=stye.split("\\|");
		for (int i = 1; i < v.length; i++) {
			String[] vs=v[i].split("-");
			if (vs.length>=2) {
				Goodstable goodstable=GoodsListFromServerUntil.fushis.get(new BigDecimal(vs[1]));
				if (goodstable!=null) {
					String[] t=goodstable.getValue().split("\\|");
					for (int j = 0; j < t.length; j++) {
						if (t[j].startsWith(type)) {
							String[] ts=t[j].split("=");
							value+=Integer.parseInt(ts[1]);
						}
					}
				}
			}
		}
		return value;
	}
	/**获取召唤兽装备的物品id集合*/
	public List<BigDecimal> getGoods(){
		if ((innerGoods==null||innerGoods.equals(""))&&(stye==null||stye.length()<=1)) {
			return null;
		}
		List<BigDecimal> goods=new ArrayList<>();
		if (innerGoods!=null&&innerGoods.equals("")) {
			String[] v=innerGoods.split("\\|");
			for (int i = 0; i < v.length; i++) {
				if (!v[i].equals("")) {
					goods.add(new BigDecimal(v[i]));
				}
			}
		}
		if (stye!=null&&stye.length()>1) {
			String[] v=stye.split("\\|");
			for (int i = 1; i < v.length; i++) {
				String[] vs=v[i].split("-");
				if (vs.length>=2) {
					goods.add(new BigDecimal(vs[1]));
				}
			}
		}
		if (goods.size()==0) {
			return null;
		}
		return goods;
	}
	/**穿脱返回这个位置原本的装备id*/
	public BigDecimal ChangePart(Goodstable goodstable,int type){
		if ((stye==null||stye.length()<=1)&&goodstable==null) {
			return null;
		}
		BigDecimal id = null;
		String ts=type+"";
		String[] v=stye.split("\\|");
		StringBuffer buffer=new StringBuffer();
		buffer.append(v[0]);
		for (int i = 1; i < v.length; i++) {
			String[] vs=v[i].split("-");
			if (ts.equals(vs[0])) {
				id=new BigDecimal(vs[1]);
			}else {
				buffer.append("|");
				buffer.append(v[i]);
			}
		}
		if (goodstable!=null) {//判断装备的位置
			buffer.append("|");
			buffer.append(type);
			buffer.append("-");
			buffer.append(goodstable.getRgid());
			String skin=null;
			String color=null;
			if (type==3) {
				String[] gv=goodstable.getValue().split("\\|");
				for (int i = 0; i < gv.length; i++) {
					String[] gvs=gv[i].split("=");
					if (gvs[0].equals("皮肤")) {
						skin=gvs[1];
					}else if (gvs[0].equals("颜色")) {
						color=gvs[1];
					}
				}
				if (skin!=null) {
					buffer.append("-");
					buffer.append(skin);
					if (color!=null) {
						buffer.append("-");
						buffer.append(color);
					}
				}
			}
		}
		stye=buffer.toString();
		return id;
	}
	/**获取装备部位的物品表id*/
	public BigDecimal getGoodId(int type){
		if (stye==null||stye.length()<=1) {
			return null;
		}
		String ts=type+"";
		String[] v=stye.split("\\|");
		for (int i = 1; i < v.length; i++) {
			String[] vs=v[i].split("-");
			if (ts.equals(vs[0])) {
				return new BigDecimal(vs[1]);
			}
		}
		return null;
	}
	public String getQuality() {
		return quality;
	}
	public void setQuality(String quality) {
		this.quality = quality;
	}
	public String getSurplusTimes() {
		return surplusTimes;
	}
	public void setSurplusTimes(String surplusTimes) {
		this.surplusTimes = surplusTimes;
	}


	public boolean isShow() {
		return show;
	}

	public void setShow(boolean show) {
		this.show = show;
	}

	public String getPetSkilllock() {
		return petSkilllock;
	}

	public void setPetSkilllock(String petSkilllock) {
		this.petSkilllock = petSkilllock;
	}

	public Integer getPetTimeLock() {
		return petTimeLock;
	}

	public void setPetTimeLock(Integer petTimeLock) {
		this.petTimeLock = petTimeLock;
	}

	public Long getTimeLock() {
		return timeLock;
	}

	public void setTimeLock(Long timeLock) {
		this.timeLock = timeLock;
	}

	public String getSummoningnameg() {
		return this.summoningnameg;
	}

	public void setSummoningnameg(final String summoningnameg) {
		this.summoningnameg = summoningnameg;
	}

	public String getXy() {
		return xy;
	}

	public void setXy(String xy) {
		this.xy = xy;
	}

	public Map<BigDecimal, Goodstable> getNeiDan() {
		return neiDan;
	}

	public void setNeiDan(Map<BigDecimal, Goodstable> neiDan) {
		this.neiDan = neiDan;
	}

	public Goodstable getCjs() {
		return cjs;
	}

	public void setCjs(Goodstable cjs) {
		this.cjs = cjs;
	}

	public Goodstable getPart1() {
		return part1;
	}

	public void setPart1(Goodstable part1) {
		this.part1 = part1;
	}

	public Goodstable getPart2() {
		return part2;
	}

	public void setPart2(Goodstable part2) {
		this.part2 = part2;
	}

	public Goodstable getPart3() {
		return part3;
	}

	public void setPart3(Goodstable part3) {
		this.part3 = part3;
	}

	public int getLzjdragon() {
		return lzjdragon;
	}

	public void setLzjdragon(int lzjdragon) {
		this.lzjdragon = lzjdragon;
	}

	public int getLzpdragon() {
		return lzpdragon;
	}

	public void setLzpdragon(int lzpdragon) {
		this.lzpdragon = lzpdragon;
	}

	public String getHhschedule() {
		return hhschedule;
	}

	public void setHhschedule(String hhschedule) {
		this.hhschedule = hhschedule;
	}

	public String getRefine() {
		return refine;
	}

	public void setRefine(String refine) {
		this.refine = refine;
	}
}